package com.tanhua.manager.controller;

import com.tanhua.domain.db.SoulOptions;
import com.tanhua.domain.db.SoulQuestion;
import com.tanhua.manager.service.SoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/soul")
public class SoulController {
    @Autowired
    private SoulService soulService;
    /**
     * 查询试卷列表
     * @return
     */
    @GetMapping("/questionnaire")
    public ResponseEntity queryQuestionnaire() {
        return soulService.queryQuestionnaire();
    }

    /**
     * 查询所有题目
     */
    @GetMapping("/question/{id}")
    public ResponseEntity queryQuestion(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize,
                                        @PathVariable("id") String id) {
        return soulService.queryQuestion(page,pagesize,id);
    }

    /**
     * 查询所有选项
     */
    @GetMapping("/option/{id}")
    public ResponseEntity queryOptions(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize,
                                        @PathVariable("id") String id) {
        return soulService.queryOptions(page,pagesize,id);
    }

    /**
     * 保存问题
     * @param questions
     * @return
     */
    @PostMapping("/question/save")
    public ResponseEntity saveQuestion(@RequestBody SoulQuestion questions) {
        return soulService.saveQuestion(questions);
    }

    /**
     * 保存选项
     * @param options
     * @return
     */
    @PostMapping("/option/save")
    public ResponseEntity saveOption(@RequestBody SoulOptions options) {
        return soulService.saveOption(options);
    }

    /**
     * 删除问题
     * @param id 问题id
     * @return
     */
    @GetMapping("/question/deleteById")
    public ResponseEntity deleteQuestionById(Integer id) {

        return soulService.deleteQuestionById(id);
    }
    /**
     * 删除选项
     * @param id 问题id
     * @return
     */
    @GetMapping("/option/deleteById")
    public ResponseEntity deleteOptionById(Integer id) {

        return soulService.deleteOptionById(id);
    }

    /**
     * 查询单个问题
     * @param id
     * @return
     */
    @GetMapping("question/findById")
    public ResponseEntity queryQuestionById(Integer id) {
        return soulService.queryQuestionById(id);
    }

    /**
     * 查询单个选项
     * @param id
     * @return
     */
    @GetMapping("option/findById")
    public ResponseEntity queryOptionById(Integer id) {
        return soulService.queryOptionById(id);
    }

}
